﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ELab.Serialization.Data;
using ELab.ImageProcess;

namespace ELab.Controls
{
    public partial class StudentControl : UserControl
    {
        public StudentControl()
        {
            InitializeComponent();
            this.Cursor = Cursors.Hand;
        }

        public event EventHandler OnUserAnswer;
        public event EventHandler OnUserLogout;
        public event EventHandler OnUserChangePass;

        private User _CurrentUser = null;
        public User CurrentUser
        {
            get { return _CurrentUser; }
            set
            {
                _CurrentUser = value;
                if (_CurrentUser == null) return;
                this.Avatar = ImageExtensions.FromByte(_CurrentUser.Avatar);
                this.StudentName = _CurrentUser.Fullname;
            }
        }

        public Image Avatar
        {
            get
            {
                return this.picAvatar.Image;
            }
            set
            {
                this.picAvatar.Image = value;
            }
        }

        public string StudentName
        {
            get
            {
                return this.lblStudentName.Text;
            }
            set
            {
                btnAnswer.Text = "Answer as " + value;
                this.lblStudentName.Text = value;
            }
        }

        public void UpdateButtonState(bool status)
        {
            ThreadHelperClass.SetEnable(this.FindForm(), btnAnswer, status);
        }

        private bool isActive = false;
        public bool IsActive
        {
            get
            {
                return isActive;
            }
            set
            {
                isActive = value;
                this.btnAnswer.Visible = value;
            }
        }

        private void btnAnswer_Click(object sender, EventArgs e)
        {
            btnAnswer.Visible = false;
            if (OnUserAnswer != null) OnUserAnswer(this, e);
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            if (OnUserLogout != null) OnUserLogout(this, e);
        }

        private void btnChangePass_Click(object sender, EventArgs e)
        {
            if (OnUserChangePass != null) OnUserChangePass(this, e);
        }
    }
}
